package han.chensing.latos.common.level.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CacheHelper {
    private static CacheHelper cacheHelper;
    private final List<File> cacheList;

    public static CacheHelper getInstance() {
        if (cacheHelper==null) cacheHelper=new CacheHelper();
        return cacheHelper;
    }

    private CacheHelper(){
        this.cacheList=new ArrayList<>();
    }

    public File createCache(String suffix) throws IOException {
        String latosQvQ = "LatosQvQ";
        File file=File.createTempFile(latosQvQ,"."+suffix);
        file.deleteOnExit();
        cacheList.add(file);
        return file;
    }

    public void cleanFiles(){
        cacheList.forEach(File::deleteOnExit);
    }
}
